package tester;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
import java.util.Timer;
import java.util.TimerTask;

import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

import xmlAnalyser.RequestAnalyser;

import dataStructures.RegisterMessage;
import dataStructures.AdapterRequest;
import dataStructures.Service;
import dataStructures.ServicesInfo;
import mainService.SuperServiceBus;
import mainService.SuperServiceBus;
import messageWrapper.MessageElement;
import messageWrapper.Message;
import messageWrapper.Packer;

public class MainTester {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SuperServiceBus esbAdapter = new SuperServiceBus();

		/*
		 * Runtime runtime = Runtime.getRuntime(); try { Process process =
		 * runtime.exec(new
		 * String[]{"javac","-sourcepath","D:/service/blog","-d"
		 * ,"D:\bin","*.java"}); process.waitFor(); } catch (IOException e) { //
		 * TODO Auto-generated catch block e.printStackTrace(); } catch
		 * (InterruptedException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */

		esbAdapter.unregistService("http://www.zyd.com/BlogService");

		RegisterMessage rms = new RegisterMessage();
		rms.setMappath("D:\\xml.xml");
		rms
				.setServiceAddress("http://localhost:8088/BlogService/BlogMainServicePort?wsdl");
		rms.setServiceName("Blog Service");
		rms.setServiceURI("http://www.zyd.com/BlogService");
		esbAdapter.registService(rms);

		ArticleCategory articleCategory = new ArticleCategory();
		articleCategory.setId(10);
		articleCategory.setLevel(50);
		articleCategory.setName("c1");

		BlogArticle blogArticle = new BlogArticle();
		blogArticle.setArticleCategory(articleCategory);
		blogArticle.setContent("testContent");
		blogArticle.setId(32);
		blogArticle.setTitle("testTitle");
		blogArticle.setCreatedTime((Calendar) Calendar.getInstance());
		blogArticle.setCategory_id(10);

		AdapterRequest req = new AdapterRequest();
		Message messagePack = new Message();

		Packer packer = new Packer("D:/xml.xml");
		messagePack = packer.wrapper(blogArticle);

		req.setArg1(new Message[]{messagePack});
		req.setOperation("postBlogArticle");
		req.setServiceURI("http://www.zyd.com/BlogService");

		RequestAnalyser ra = new RequestAnalyser();
		ra.analyse(req);
		Object[] os = ra.getArgs();
		// service.http.www.zyd.com.BlogService.BlogArticle ba =
		// (service.http.www.zyd.com.BlogService.BlogArticle) os[0];
		// service.http.www.zyd.com.BlogService.ArticleCategory ac =
		// ba.getArticleCategory();

		/*Message res = esbAdapter.doWork(req);
		String[] list = res.getFieldList();
		for (int i = 0; i < list.length; i++) {
			String fieldname = list[i];
			MessageElement te = res.getElement(fieldname);
			String fieldtype = te.getType();
			String fieldvalue = te.getValue().toString();
			System.out.print(fieldname + "  " + fieldtype + "  " + fieldvalue
					+ "\n");
		}*/

	}

}
